from flask_restful import Resource
from flask_jwt_extended import jwt_required, get_jwt_identity
from models.user import UserModel
from common.res import res


class Me(Resource):
    """获取我的信息"""

    @jwt_required()
    def get(self):
        user_name = get_jwt_identity()
        try:
            user = UserModel.query.filter_by(user_name=user_name).first()
        except Exception as e:
            print(f"user {e}")
            return "user-err"

        if user:
            data = {
                "user_id": user.id,
                "user_name": user.user_name,
                "avatar": user.avatar,
                "profile": "",
                "gender": 1,
                "following": 0,
                "follower": 0,
            }

            return res(data=data)


class GetUserInfo(Resource):
    """获取用户信息"""

    def post(self):
        return "user-err"
